package com.usefullc.system.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.usefullc.system.domain.AppDevice;
import com.usefullc.system.domain.LocalInfo;
import com.usefullc.system.domain.LocalInfoDetail;
import com.usefullc.system.mapper.LocalInfoDetailMapper;
import com.usefullc.system.query.BaseQuery;
import com.usefullc.system.query.LocalInfoDetailQuery;
import com.usefullc.system.query.LocalInfoQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author: Sampson
 * @date: 2018-12-20 18:37
 */
@Service
public class LocalInfoDetailService extends AbstractBizService<LocalInfoDetailMapper,LocalInfoDetail,LocalInfoDetailQuery> {

    @Autowired
    private LocalInfoService localInfoService;


    /**
     * 获取db中的国际化值，后续走缓存 TODO
     * @param appType
     * @param bizType
     * @param language
     * @param key
     * @return
     */
    public String findByKey(String appType,Integer bizType,String language,String key){
        LocalInfoQuery localInfoQuery = new LocalInfoQuery();
        localInfoQuery.setAppType(appType);
        localInfoQuery.setType(bizType);
        localInfoQuery.setKey(key);
        LocalInfo localInfo = localInfoService.findOne(localInfoQuery);
        if(localInfo == null){
            return null;
        }
        LocalInfoDetailQuery localInfoDetailQuery = new LocalInfoDetailQuery();
        localInfoDetailQuery.setInfoId(localInfo.getId());
        localInfoDetailQuery.setLanguage(language);
        LocalInfoDetail localInfoDetail = this.findOne(localInfoDetailQuery);
        if(localInfoDetail != null){
            return localInfoDetail.getContent();
        }
        return null;
    }

    @Override
    public QueryWrapper<LocalInfoDetail> getQueryWrapper(LocalInfoDetailQuery query) {
        QueryWrapper<LocalInfoDetail> queryWrapper = super.getQueryWrapper(query);
        return queryWrapper;
    }
}
